package com.itheima.mapper;

import com.itheima.entity.Emp;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
//当项目运行的时候 spring扫描会扫描到这个接口 并调用mybatis的动态代理
//帮我们生成一个持久层的对象 存放到spring的ioc容器中

public interface EmpMappper {

    //1.查询所有员工
    @Select("select *from tb_emp")
    public List<Emp> findAll();

    //2.根据id查询单个员工
    @Select("select *from tb_emp where id=#{id}")
    public Emp findById(Integer id);

    //3.新增员工
    @Insert("insert into tb_emp(id, username, password, name, gender, image, job, entrydate, create_time, update_time) " +
            "values (#{id}, #{username}, #{password}, #{name}, #{gender}, #{image}, #{job}, #{entrydate},  #{create_time}, #{update_time})")
    public int addUser(Emp emp);

    //4.根据id删除员工
    @Delete("delete from tb_emp where id=#{id}")
    public int deleteById(Integer id);

    //5.根据id修改员工
    @Update("update tb_emp set " +
            "username = #{username}, " +
            "password = #{password}, " +
            "name = #{name}, " +
            "gender = #{gender}, " +
            "image = #{image}, " +
            "job = #{job}, " +
            "entrydate = #{entrydate}, " +
            "create_time = #{create_time}, " +
            "update_time = #{update_time} " +
            "where id = #{id}")
    public int updateUser(Emp emp);


}
